/*
 *  Copyright (c) Skrumtious
 */
package com.skrumtious.action;

import com.skrumtious.action.bean.ErrorBean;
import com.skrumtious.action.bean.SkrumListingBean;
import com.skrumtious.backend.DoGetSkrumListRequest;
import com.skrumtious.backend.DoGetSkrumListResponse;
import com.skrumtious.backend.SkrumService;
import com.skrumtious.backend.SkrumServiceFactory;

/**
 * The main action of the website, this retrieves the tab lists
 * and tasks in the tabs.
 * 
 * @author Tony
 *
 */
public class GetSkrumListWebAction implements WebAction {

	/* (non-Javadoc)
	 * @see com.skrumtious.action.WebAction#doAction(com.skrumtious.action.WebRequest)
	 */
	@Override
	public WebResponse doAction(WebRequest request) throws Exception {
		WebResponse response = null;
		
		SkrumService skrumService = SkrumServiceFactory.getSkrumService();
		
		DoGetSkrumListRequest skrumRequest = new DoGetSkrumListRequest(request.getUserId());
		DoGetSkrumListResponse skrumResponse = skrumService.getSkrumList(skrumRequest);
		
		
		if ( ! skrumResponse.isSuccess() ) {
			String errorMsg = skrumResponse.getHumanReadableError();
			ErrorBean errorBean = new ErrorBean(errorMsg);
			request.setBean(ErrorBean.BEAN_NAME, errorBean);
			
			response = new WebResponse(true, false, "error.jsp");
		}
		else {			
			SkrumListingBean listingBean = new SkrumListingBean(0, skrumResponse);
			request.setBean(SkrumListingBean.BEAN_NAME, listingBean);
			
			response = new WebResponse(true, false, "skrumlist.jsp");
		}
						
		return response;
	}

}
